//
//  YDTabBarController.swift
//  YDRxReadBook
//
//  Created by rowena on 2018/12/26.
//  Copyright © 2018年 wuyezhiguhun. All rights reserved.
//

import UIKit

class YDTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.addAllViewControllers()
    }
    
}

extension YDTabBarController {
    
    /** 添加所有的控制器 */
    func addAllViewControllers() {
        self.addChildController(controller: YDBookcaseController(), title: "书架", imageName: "read_book_bookcase")
        self.addChildController(controller: YDBookstoreController(), title: "书城", imageName: "read_book_bookstore")
        self.addChildController(controller: YDSearchController(), title: "搜索", imageName: "read_book_search")
        self.addChildController(controller: YDUserController(), title: "我", imageName: "read_book_user")
    }
    
    /** 添加每个子控制器 */
    func addChildController(controller: UIViewController, title: String, imageName: String) {
        let navigationController = UINavigationController(rootViewController: controller)
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName)
        self.addChild(navigationController)
    }
    
}

